import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import set from '@dfeidao/atom-mobile/local/set';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import goto_param from '@dfeidao/atom-mobile/nav/get-param';
import render from '@dfeidao/atom-mobile/render/render';
import whoami_getparams from '../atom/whoami_getparams';
export default async function a001(fd: IFeidaoAiMobile) {
	// 初始/切换页签
	let params = get(fd, 'params') as { productid: string };
	if (!params) {
		const user = await whoami_getparams(fd) as {
			params: {
				teacher_name: string;
				productid: string;
				teacher_no: string;
			}
		};
		params = user.params;
		set(fd, 'params', params);
	}
	const type = get(fd, 'type') || 1;
	const sign_in = get(fd, 'sign_in') || 1;
	const class_id = goto_param(fd, 'class_id');
	const productid = params.productid;
	const page_no = get(fd, 'page_no') || 1;
	const page_size = 20;
	let res = await nodejs('app-check-status/s001', {
		productid,
		class_id,
		page_no,
		page_size,
		type, // 1 签到和未签到/2 请假
		sign_in// 2 签到/1 未签到
	}) as Array<{}>;
	const t = res.length;
	if (page_no !== 1) {
		const data = get(fd, 'res') as [{}];
		res = data.concat(res);
	}
	set(fd, 'res', res);
	if (type === 1 && sign_in === 1) {
		render(fd, { wqd: res, t });
	} else if (type === 1 && sign_in === 2) {
		render(fd, { yqd: res, t });
	} else {
		render(fd, { qj: res, t });
	}
}
